/*******************************************************************************

This code file produces Table A11, "Bootstrap Estimates of Citywide Supply Response and Marginal Fiscal Cost, Alternative Specifications."

*******************************************************************************/

*** Manage settings

	run "$dir/code/modules/settings.do"
	
* Load Stata-TeX

	do "$code/modules/stata-tex.do"
	cd "$tables/estimates"
	
	local n_boot = 200
	local n_boot_gmm = 20
		
********************************************************************************
* Main
********************************************************************************	
	
*** Elasticity

	* RE logit
	
	use "$data/clean/cleaned_data.dta", clear
	
	do "$code/modules/bootstrap_programs.do"
	
	bootstrap tmp=r(tmp), reps(`n_boot') seed(1234) cluster(nta) idcluster(nta_boot): boot_elasticity_relogit
	
	matrix mat_elasticity = r(table)
	local elasticity_estimate = mat_elasticity[1,1]
	local elasticity_stderr = mat_elasticity[2,1]
	
	insert_into_file using tableA11.csv, key(elast_relogit_est) value(`elasticity_estimate') format(%12.2f)
	insert_into_file using tableA11.csv, key(elast_relogit_se) value(`elasticity_stderr') format(%12.2f) 

	* Probit
	
	use "$data/clean/cleaned_data.dta", clear
	
	do "$code/modules/bootstrap_programs.do"
	
	bootstrap tmp=r(tmp), reps(`n_boot') seed(1234) cluster(nta) idcluster(nta_boot): boot_elasticity_probit
	
	matrix mat_elasticity = r(table)
	local elasticity_estimate = mat_elasticity[1,1]
	local elasticity_stderr = mat_elasticity[2,1]
	
	insert_into_file using tableA11.csv, key(elast_probit_est) value(`elasticity_estimate') format(%12.2f)
	insert_into_file using tableA11.csv, key(elast_probit_se) value(`elasticity_stderr') format(%12.2f) 
	
	* LPM
	
	use "$data/clean/cleaned_data.dta", clear
	
	do "$code/modules/bootstrap_programs.do"
	
	bootstrap tmp=r(tmp), reps(`n_boot') seed(1234) cluster(nta) idcluster(nta_boot): boot_elasticity_lpm
	
	matrix mat_elasticity = r(table)
	local elasticity_estimate = mat_elasticity[1,1]
	local elasticity_stderr = mat_elasticity[2,1]
	
	insert_into_file using tableA11.csv, key(elast_lpm_est) value(`elasticity_estimate') format(%12.2f)
	insert_into_file using tableA11.csv, key(elast_lpm_se) value(`elasticity_stderr') format(%12.2f) 

*** Marginal cost

	* RE logit
	
	use "$data/clean/cleaned_data.dta", clear
	
	do "$code/modules/bootstrap_programs.do"
	
	bootstrap tmp=r(tmp), reps(`n_boot') seed(1234) cluster(nta) idcluster(nta_boot): boot_mcost_relogit
	
	matrix mat_mcost = r(table)
	local mcost_estimate = mat_mcost[1,1]
	local mcost_stderr = mat_mcost[2,1]
	
	insert_into_file using tableA11.csv, key(mcost_relogit_est) value(`mcost_estimate') format(%12.0fc)
	insert_into_file using tableA11.csv, key(mcost_relogit_se) value(`mcost_stderr') format(%12.0fc) 

	* Probit
	
	use "$data/clean/cleaned_data.dta", clear
	
	do "$code/modules/bootstrap_programs.do"
	
	bootstrap tmp=r(tmp), reps(`n_boot') seed(1234) cluster(nta) idcluster(nta_boot): boot_mcost_probit
	
	matrix mat_mcost = r(table)
	local mcost_estimate = mat_mcost[1,1]
	local mcost_stderr = mat_mcost[2,1]
	
	insert_into_file using tableA11.csv, key(mcost_probit_est) value(`mcost_estimate') format(%12.0fc)
	insert_into_file using tableA11.csv, key(mcost_probit_se) value(`mcost_stderr') format(%12.0fc) 
	
	* LPM
	
	use "$data/clean/cleaned_data.dta", clear
	
	do "$code/modules/bootstrap_programs.do"
	
	bootstrap tmp=r(tmp), reps(`n_boot') seed(1234) cluster(nta) idcluster(nta_boot): boot_mcost_lpm
	
	matrix mat_mcost = r(table)
	local mcost_estimate = mat_mcost[1,1]
	local mcost_stderr = mat_mcost[2,1]
	
	insert_into_file using tableA11.csv, key(mcost_lpm_est) value(`mcost_estimate') format(%12.0fc)
	insert_into_file using tableA11.csv, key(mcost_lpm_se) value(`mcost_stderr') format(%12.0fc) 

			
********************************************************************************
* Create table
********************************************************************************
	
	cat tableA11.csv

	cap erase "$tables/output/tableA11.tex"

	cd "$code/modules"
	capture table_from_tpl, t("$tables/templates/tableA11.tex") ///
							r("$tables/estimates/tableA11.csv") ///
							o("$tables/output/tableA11.tex") 
			
	capture table_from_tpl, t("$tables/templates/tableA11.tex") ///
							r("$tables/estimates/tableA11.csv") ///
							o("$tables_overleaf/tableA11.tex") 
							
	exit

	
